// 新增会员
<template>
    <div>
        <GoBack></GoBack>
        <div class="AddUserBox">
            <p class="adselfBox">新增会员</p>
            <div class="add-user-cont">
                <div class="radioBox flex flex-align-center">
                    <p>开户类型</p>
                    <el-radio v-model="radio" :label="item.member_type" v-for='(item,index) in addWinData.member' :key='index'>{{item.name}}</el-radio>
                </div>
                <p class="add-tips">{{name}}{{remaining}}</p>
                <div class="inputBox flex flex-align-center">
                    <p>用户名</p>
                    <input type="text" v-model.trim='nickName'>
                    <div class="flex flex-align-center" v-if="isTips != ''">
                        <img src="@/assets/img/user-center/tx-jysb.png" alt="">
                        <p style="font-size:0.1rem">{{isTips}}</p>
                    </div>
                </div>
                <p class="timeLin">软件使用时间 <span>{{addWinData.use_time}}</span></p>
                <p class="pwdLin">密码（预设） <span>{{addWinData.default_password}}</span></p>
                <div class="addBtn flex flex-align-center  flex-pack-center" @click="addUserPostFun"><p>新增</p></div>
            </div>
        </div>
        <div class="addModel" v-if='isWind'>
            <div class="addModelBox">
                <div class="addModelHead flex flex-align-center">
                    <p class="title">开户信息</p>
                    <img src="@/assets/img/business/business-close.png" alt="" @click="onCloseWinFun">
                </div>
                <div class="addModelCont">
                    <p>{{childData.info}}</p>
                    <p class="xiaji">下级账号<span>{{childData.user_name}}</span></p>
                    <p>密码(预设)<span>{{childData.password}}</span></p>
                    <!-- <p>下载地址 <input type="text" id='textCont' readonly='readonly' :value="childData.download_url"></p> -->
                    <p>下载地址 <textarea type="text" id='textCont' readonly='readonly' :value="childData.download_url"> </textarea></p>
                    <div class="flex btnGroup">
                    <div class="copyBtn flex flex-align-center  flex-pack-center" @click="onCopyFun"><p>复制</p></div>
                    <div class="copyBtn flex flex-align-center  flex-pack-center" @click="addUserQuerenFun"><p>确认</p></div>
                </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import GoBack from '../goback'
import https from '@/public/https'
export default {
    components: {
        GoBack
    },
    data () {
        return {
             radio: null,
             isWind:false,
             addWinData:[],
             remaining:'',
             name:'',
             nickName:'',
             childData:[],
             isTips:'',
        }
    },
    mounted () {
        this.getAddUserInfo();
    },
    watch: {
        radio(news,old){
            for(var i in this.addWinData.member){
                if(this.addWinData.member[i].member_type == news){
                    this.name = this.addWinData.member[i].name;
                    this.radio = this.addWinData.member[i].member_type;
                    this.remaining = this.addWinData.member[i].remaining.replace('(','').replace(')',''); 
                }
            }
        },
        nickName(news,old){
            this.isTips ='';
        }
    },
    methods: {
        getAddUserInfo(){
            let uid = this.$store.state.userInfo.id;
            this.https('user/getObtainUserMemberCount',{uid:uid})
            .then(data => {
               this.name = data.member[0].name;
               this.radio = data.member[0].member_type;
               this.remaining = data.member[0].remaining;
               this.addWinData = data;
            })   
        },
        onCloseWinFun(){
            this.isWind = false;
        },
        addUserQuerenFun(){
             this.isWind = false;
        },
        onCopyFun(){
            let text=document.getElementById("textCont");
            text.select(); // 选择对象
            document.execCommand("Copy");  //执行浏览器拷贝
        },

        // 提交新开下级用户信息
        addUserPostFun(){
            if(this.nickName != '' && this.radio != null){
                https.post('user/postAddUser',{member_type:this.radio,user_name:this.nickName})
                .then(data =>{
                    if(data.status == 1){
                        this.childData = data.data;
                        this.isWind=true;
                        this.postObtainUserInfoByUid();
                    }else{
                        this.isTips = data.message;
                    }
                })
            }
        },

        // 查询用户详情
        postObtainUserInfoByUid(){
             this.https('User/postObtainUserInfoByUid',{},'post')
             .then(data => {
                    data.use_end_time = this.format(data.use_end_time,1);
                    this.$store.commit('setUserInfo',data);
             });
        }
    }
}
</script>
<style lang="less" scoped>
@import url(../../assets/css/usercenter/adduser.less);
</style>

